home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 May: Tool Chest / Dev.CD May 98 TC.toast / Tool Chest / Development Kits / HyperCard Related / APDA HyperCard Toolkits / HyperCard CTB Toolkit 1.0b2 / Source Code / CTBState.p < prev    next >
Encoding:
Text File  |  1995-02-07  |  1.8 KB  |  72 lines  |  [TEXT/MPS ]

  1. (*
  2.     CTBState() -- Return the state of the current connection: "closed", "opening", "open", "closing".
  3.  
  4.     To compile and link this file using Macintosh Programmer's Workshop,
  5.  
  6.         pascal -w CTBState.p
  7.         link -m ENTRYPOINT -o HyperCommands -rt XFCN=2753 -sn Main=CTBState ∂
  8.             CTBState.p.o "{MPW}"Libraries:interface.o "{MPW}"Libraries:Libraries:HyperXLib.o
  9.  
  10.     © Copyright 1990 by Apple Computer, Inc.
  11.  
  12.     Initial coding 2/90 by Harry R. Chesley.
  13. *)
  14.  
  15. {$R-}
  16.  
  17. {$S CTBState }     { Segment name must be the same as the command name. }
  18.  
  19. unit DummyUnit;
  20.  
  21. interface
  22.  
  23. uses MemTypes, QuickDraw, OSIntf, ToolIntf, CTBUtils, FTIntf, CMIntf, TMIntf, CRMIntf, HyperXCmd;
  24.  
  25. procedure EntryPoint(paramPtr: XCmdPtr);
  26.     
  27. implementation
  28.  
  29. procedure CTBState(paramPtr: XCmdPtr); forward;
  30.  
  31. procedure EntryPoint(paramPtr: XCmdPtr);
  32.  
  33.     begin
  34.         CTBState(paramPtr);
  35.     end;
  36.  
  37. procedure CTBState(paramPtr: XCmdPtr);
  38.  
  39.     {$I CTBUtil.inc}
  40.  
  41.     var sizes: CMBufferSizes;
  42.         status: CMStatFlags;
  43.         s: Str255;
  44.  
  45.     procedure Fail(errMsg: Str255); { set theResult and quit }
  46.         begin
  47.             paramPtr^.returnValue := PasToZero(paramPtr,errMsg);
  48.             exit(CTBState);
  49.         end;
  50.  
  51.     begin
  52.         { Check the parameter count. }
  53.         if paramPtr^.paramCount <> 0 then Fail('Invalid parameter count');
  54.  
  55.         { Make sure the Comm Toolbox is present. }
  56.         CTBReady;
  57.  
  58.         { Convert the state to a string. }
  59.         if Globals^^.connHand = nil then status := 0
  60.         else if CMStatus(Globals^^.connHand,sizes,status) <> noErr then status := 0;
  61.         if (BAnd(status,cmStatusOpening) <> 0) or
  62.             (BAnd(status,cmStatusListenPend+cmStatusIncomingCallPresent) <> 0) then s := 'opening'
  63.         else if BAnd(status,cmStatusClosing) <> 0 then s := 'closing'
  64.         else if BAnd(status,cmStatusOpen) <> 0 then s := 'open'
  65.         else s := 'closed';
  66.  
  67.         { Return it. }
  68.         paramPtr^.returnValue := PasToZero(paramPtr,s);
  69.     end;
  70.  
  71. end.
  72.